package LeetCode;

public class LC_374_GuessNumberHigherorLower {

    public static void main(String[] args) {

    }

    class GuessGame {
        int guess(int num) {
            //guess
            return 0;
        }
    }

    public class Solution extends GuessGame {
        public int guessNumber(int n) {
            int L = 1, R = n;
            while (L <= R) {
                int mid = L + ((R - L) >> 1);
                int res = guess(mid);
                if (res == 0) return mid;
                else if (res == 1) L = mid + 1;
                else R = mid - 1;
            }
            return L;
        }
    }

    class Solution_2 extends GuessGame {
        public int guessNumber(int n) {
            int low = 1;
            int high = n;
            while (low <= high) {
                int mid = low + ((high - low) / 2);
                int result = guess(mid);
                if (result == 0) return mid;
                else if (result == 1) low = mid + 1;
                else high = mid - 1;
            }
            return -1;
        }
    }

}